package com.ruoyi.demo.service.impl;

import com.ruoyi.demo.DTO.CreateUserMeetDetailsDTO;
import com.ruoyi.demo.domain.CreatedMeet;
import com.ruoyi.demo.mapper.CreateMeetSysUserMapper;
import com.ruoyi.demo.mapper.CreateUserMeetMapper;
import com.ruoyi.demo.mapper.CreateUserMeetDetailsMapper;
import com.ruoyi.demo.service.ICreateUserMeetDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CreateUserMeetDetailsServiceImpl implements ICreateUserMeetDetailsService {
    @Autowired
    private CreateUserMeetMapper meetMapper;

    @Autowired
    private CreateMeetSysUserMapper sysUserMapper;

    @Autowired
    private CreateUserMeetDetailsMapper meetDetailsMapper;

    @Override
    public CreateUserMeetDetailsDTO getMeetDetails(Long meetId) {
        // 获取会议详细信息
        CreatedMeet meet = meetMapper.getMeetById(meetId);
        if (meet == null) {
            return null;
        }

        // 获取会议创建者的用户名
        String userName = sysUserMapper.getUserNameById(meet.getUserId());

        // 获取参会人员姓名列表
        List<String> attendUserNames = meetDetailsMapper.getAttendUserNames(meetId);

        // 构建 MeetDetailsDTO
        CreateUserMeetDetailsDTO meetDetails = new CreateUserMeetDetailsDTO();
        meetDetails.setMeetId(meet.getMeetId());
        meetDetails.setTheme(meet.getTheme());
        meetDetails.setMeetContent(meet.getMeetContent());
        meetDetails.setStartTime(meet.getStartTime());
        meetDetails.setEndTime(meet.getEndTime());
        meetDetails.setNumRespondents(meet.getNumRespondents());
        meetDetails.setActualNum(meet.getActualNum());
        meetDetails.setStatus(meet.getStatus());
        meetDetails.setCreatedAt(meet.getCreatedAt());
        meetDetails.setUpdateAt(meet.getUpdateAt());
        meetDetails.setRating(meet.getRating());
        meetDetails.setUserId(meet.getUserId());
        meetDetails.setRoomId(meet.getRoomId());
        meetDetails.setRejection(meet.getRejection());
        meetDetails.setUserName(userName);
        meetDetails.setRoomAddress(meet.getRoomAddress());
        meetDetails.setAttendUserNames(attendUserNames);  // 设置参会人员姓名列表

        return meetDetails;
    }
}
